package hu.mapro.gwtui.server;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.Lists;
import com.google.web.bindery.requestfactory.server.RequestFactoryServlet;
import com.google.web.bindery.requestfactory.server.ServiceLayerDecorator;
import com.google.web.bindery.requestfactory.shared.ServerFailure;

@SuppressWarnings("serial")
public class GwtUiRequestFactoryServlet extends RequestFactoryServlet {

	private static class ExceptionHandler implements com.google.web.bindery.requestfactory.server.ExceptionHandler {

		private static final Logger LOG = LoggerFactory
				.getLogger(ExceptionHandler.class);

		@Override
		public ServerFailure createServerFailure(Throwable throwable) {
			LOG.error("Server error", throwable);
			return new ServerFailure(throwable.getMessage(), throwable
					.getClass().getName(), null, true);
		}
	}

	protected GwtUiRequestFactoryServlet(ServiceLayerDecorator... serviceDecorators) {
		super(new ExceptionHandler(), Lists.asList(new GwtUiServiceLayerDecorator(), serviceDecorators).toArray(new ServiceLayerDecorator[0]));
	}
}
